import Mock from "mockjs";

const data = Mock.mock({
  // 20条数据
  "data|55": [
    {
      // 商品种类
      name: "@cname",
      modelName: "@ctitle(3)",
      "modelId|+1": 1,
      modelAddress: "@county(true)",
      "modelSale|30-500": 30,
      "time|1648000870324-1648000853323": 1648000870324,
    },
  ],
});

interface DataType {
  page: number;
  size: number;
}

class WelcomeServer {
  getData(obj: DataType) {
    const { page, size } = obj;
    const result = data.data.slice((page - 1) * size, page * size);
    return new Promise((resolve) => {
      resolve({
        status: 0,
        data: result,
        count: data.data.length,
      });
    });
  }
  delData(id: number) {
    data.data = data.data.filter((item: any) => item.modelId !== id);
    return new Promise((resolve) => {
      resolve({
        status: 0,
        msg: "删除成功",
      });
    });
  }
}

const welcome = new WelcomeServer();
export default welcome;
